import Taro, {Component} from "@tarojs/taro";
import {View, RichText } from "@tarojs/components";
import {toJS} from 'mobx'
import {inject, observer} from '@tarojs/mobx'
import {IStoreProps} from '../../store/Stores'
import {getRuntime} from '../../utils/common'

import './help_detail.less'

// 问题详情
interface IHomeProps extends IStoreProps {}

@inject("stores")
@observer
class HelpDetail extends Component<IHomeProps> {
  constructor(props) {
    super(props)
  }

  state = {
    info: {}
  }

  componentWillMount(): void {
    Taro.setNavigationBarTitle({ title:'问题详情' })
    let id = this.$router.params.id
    this.getDoubtAnswer(parseInt(id))
  }

  handelRouter(url: string = '/pages/index/index'): void {
    getRuntime().navigateTo(url)
  }

  getDoubtAnswer(id:number) {
    let { userStore } = this.props.stores
    userStore.getDoubtAnswer({
      formId: id,
      callback: res => {
        this.setState({info: toJS(res)})
      }
    })
  }

  render() {
    let { info } = this.state
    return (
      <View className='my-help-detail'>
        <View className='list-title'>{info['title']}</View>
        <View className='article-wrap article rich-text'>
          <RichText nodes={info['content']} />
          {info}
        </View>
      </View>
    )
  }
}

export default HelpDetail
